﻿//
// Copyright (c) 2024 BPer
//

#ifndef BPERDECODER_SRC_BPERH264DECODERSOFT_H_
#define BPERDECODER_SRC_BPERH264DECODERSOFT_H_
#include <bperdecoder/BPerVideoDecoder.h>
#include <bperutil/sys/BPerLoadLib.h>
#include <bperutil/BPerType.h>

extern "C"{
#include <bperdecoder/BPerH264Dec.h>
}

class BPerH264DecoderSoft: public BPerVideoDecoder {
public:
	BPerH264DecoderSoft();
	virtual ~BPerH264DecoderSoft();
	void parseRtmpHeader(uint8_t *p, int32_t pLen, int32_t *pwid, int32_t *phei, int32_t *pfps);
	void init();
	int32_t decode(BPerFrame* videoFrame,BPerColorSpace yuvtype,BPerDecoderCallback* pcallback);

private:
	uint8_t* m_buffer;
	int32_t m_bufLen;
private:
	struct BPerH264DecContext *context;
	void getH264RtmpHeader(uint8_t *buf, uint8_t *src, int32_t *hLen);
#if	BPer_Enable_H264Decoder_So
	BPerLoadLib m_lib;

	struct BPerH264DecContext* (*bPer_getBPerH264DecContext)();
	//void  (*bPer_parseHeader)(uint8_t *p,int32_t pLen,int32_t *pwid,int32_t *phei,int32_t *pfps);
	void (*bPer_init_H264DecCont)(struct BPerH264DecContext *cont,
			uint8_t *headers, int32_t headerLen);
	int32_t (*bPer_decode)(struct BPerH264DecContext *cont, int32_t isIframe,
			uint8_t *pData, int32_t nSize, enum BPerYuvType pyuvType,uint8_t *dest,
			int32_t *pnFrameReturned);
	void (*bPer_decode_close)(struct BPerH264DecContext *cont);
#else
	#define bPer_getBPerH264DecContext getBPerH264DecContext
	//#define bPer_parseHeader  parseHeader
	#define bPer_init_H264DecCont init_H264DecCont
    //#define bPer_decode decode
	#define bPer_decode_close decode_close
#endif
};

#endif /* BPERDECODER_SRC_BPERH264DECODERSOFT_H_ */
